package cn.schoolwow.util.test.module.query.queryPackage.service;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.queryPackage.QueryPackage;
import cn.schoolwow.util.domain.query.queryPackage.QueryPackageResponse;
import cn.schoolwow.util.test.module.query.queryPackage.domain.FlowRecordable;
import org.junit.Assert;

import java.util.List;

public class QueryPackageTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowRecordTest();
        businessFlowTest();
    }

    @Override
    public String name() {
        return "获取类列表测试用例";
    }

    private void flowRecordTest(){
        QueryPackageResponse queryPackageResponse = QueryPackage.newQuery("cn.schoolwow.util.test.module.query.queryPackage.impl")
                .classNameSuffix("FlowRecordable")
                .addClassQuery(FlowRecordable.class)
                .execute();
        List<Class> classList = queryPackageResponse.getClassList();
        Assert.assertEquals(1, classList.size());
        Assert.assertEquals("ResetUserFlowRecordable",classList.get(0).getSimpleName());

        List<FlowRecordable> flowRecordList = queryPackageResponse.getInstanceList(FlowRecordable.class);
        Assert.assertEquals(1, flowRecordList.size());
    }

    private void businessFlowTest(){
        List<BusinessFlow> list = QueryPackage.newQuery("cn.schoolwow.util.test.module.query.queryPackage.impl")
                .addClassQuery(BusinessFlow.class)
                .execute()
                .getInstanceList(BusinessFlow.class);
        Assert.assertEquals(1, list.size());

        Assert.assertEquals("重置用户流程记录", list.get(0).name());
    }
}
